#define DEBUG
#include <cstdio>

using namespace std;

typedef long long ll;

const int maxn=300000, maxm=300000;

class PairHeap {
public:
  ll v, marka, markb;
  int id;
  PairHeap *son, *bro;

  PairHeap(int x, ll val) {
    id = x, v = val;
    marka = 1, markb=0;
    son = bro = NULL;
  }

  PairHeap* markDown() {
    if (marka!=1 || markb!=0) {
      if (son) {
        son->markb = marka*son->markb+markb;
        son->marka *= marka;
      }
      if (bro) {
        bro->markb = marka*bro->markb+markb;
        bro->marka *= marka;
      }
      v = marka*v+markb;
      marka = 1, markb = 0;
    }
    return this;
  }

  static PairHeap* merge(PairHeap *a, PairHeap *b) {
    if (!a) {
      return b;
    }
    if (!b) {
      return a;
    }
    a->markDown(), b->markDown();
    if (a->v<=b->v) {
      b->bro = a->son;
      a->son = b;
      return a;
    } else {
      a->bro = b->son;
      b->son = a;
      return b;
    }
  }

  PairHeap* merges() {
    if (!this || !bro) {
      return this;
    } else {
      PairHeap *a=bro, *b=a->bro;
      this->markDown(), a->markDown();
      bro = a->bro = NULL;
      return merge(merge(this, a), b->merges());
    }
  }
};

class Tree {
public:
  int son[maxn+1], bro[maxn+1], dep[maxn+1];

  void addSide(int f, int s) {
    bro[s] = son[f];
    son[f] = s;
    dep[s] = dep[f]+1;
  }
};

int main() {
  freopen("fall.in", "r", stdin);
  freopen("fall.out", "w", stdout);

  static PairHeap* heap[maxn+1];
  static Tree tree;
  static ll a[maxn+1], v[maxn+1], h[maxn+1];
  static int cas[maxn+1], kni[maxm+1], c[maxm+1];
  int n, m;
  scanf("%d %d", &n, &m);
  for (int i=1; i<=n; i++) {
    scanf("%lld", &h[i]);
  }
  tree.dep[1] = 1;
  for (int i=2; i<=n; i++) {
    int f;
    scanf("%d %lld %lld", &f, &a[i], &v[i]);
    tree.addSide(f, i);
  }

  for (int i=1; i<=m; i++) {
    ll s;
    scanf("%lld %d", &s, &c[i]);
    heap[c[i]] = PairHeap::merge(heap[c[i]], new PairHeap(i, s));
  }


  for (int i=n; i>0; i--) {
    for (int x=tree.son[i]; x; x=tree.bro[x]) {
      heap[i] = PairHeap::merge(heap[i], heap[x]);
    }
    for (; heap[i] && heap[i]->markDown()->v<h[i]; ) {
      kni[heap[i]->id] = tree.dep[i];
      cas[i]++;
      heap[i] = heap[i]->son->merges();
    }
    if (heap[i]) {
      heap[i]->markDown();
      if (a[i]) {
        heap[i]->marka *= v[i];
      } else {
        heap[i]->markb += v[i];
      }
      heap[i]->markDown();
    }
  }

  for (int i=1; i<=n; i++) {
    printf("%d\n", cas[i]);
  }
  for (int i=1; i<=m; i++) {
    printf("%d\n", tree.dep[c[i]]-kni[i]);
  }

  fclose(stdin);
  fclose(stdout);
  return 0;
}
